package com.example.teamtribe.hello;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;

import com.example.teamtribe.R;
import com.example.teamtribe.base.BaseActivity;
import com.example.teamtribe.main.HomeActivity;
import com.example.teamtribe.utils.Utility;

public class CoverActivity extends BaseActivity implements View.OnClickListener{

    LocalBroadcastManager localBroadcastManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cover);

        localBroadcastManager = LocalBroadcastManager.getInstance(this);
        findViewById(R.id.bt_login).setOnClickListener(this);
        findViewById(R.id.bt_register).setOnClickListener(this);

        localBroadcastManager.registerReceiver(this.finishAppReceiver, new IntentFilter("HELLO_FINISH"));

        if (Utility.isLogged()) {
            startActivity(new Intent(CoverActivity.this, HomeActivity.class));
        }
    }

    protected BroadcastReceiver finishAppReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            finish();
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        localBroadcastManager.unregisterReceiver(this.finishAppReceiver);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_login:
                startActivity(new Intent(CoverActivity.this, LoginActivity.class));
                break;

            case R.id.bt_register:
                startActivity(new Intent(CoverActivity.this, RegisterActivity.class));
                break;

            default:
                break;
        }
    }
}
